package com.ant.myagile

import static org.junit.Assert.*

import grails.test.mixin.*
import grails.test.mixin.support.*
import java.text.DateFormat
import java.text.ParseException
import java.text.SimpleDateFormat
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
 */
@TestFor(TeamService)
@Mock([Team, Project, Team_Project, Tracking])
class TeamServiceTest {

	void setUp() {
		Team ant = new Team(teamName: "Ant", mailGroup: "ant@axonactive.vn", establishedDate: "06/03/2013").save(failOnError: true)
	}

	void tearDown() {

		def ant = Team.findByTeamName("Ant")

		if(ant != null) ant.delete(flush: true)
	}

	void testSaveTeam() {
		assert Team.count() == 1
		TeamService teamService = new TeamService()
		def teamName = "abc"
		def  mailGroup = "abc@gmail.com"
		def description = "tea"
		Date date;
		try{
			DateFormat formatter;
			formatter = new SimpleDateFormat("yyyy-MM-dd");
			date = (Date) formatter.parse("2012-07-06")
			println "established date create  "+ date
		}catch(ParseException ex){
			ex.printStackTrace();
		}
		teamService.save_Team(teamName, mailGroup, description, date, null, null)
		assert Team.count() == 2
	}
	void testUpdateTeam(){
		TeamService teamService = new TeamService()
		def team = Team.findByTeamName('Ant')
		def teamName = "abc"
		def  mailGroup = "abc@gmail.com"
		def description = "tea"
		
		Date date;

		try{
			DateFormat formatter;
			formatter = new SimpleDateFormat("yyyy-MM-dd");
			date = (Date) formatter.parse("2012-07-06")
			println "established date create  "+ date
		}catch(ParseException ex){
			ex.printStackTrace();
		}
		teamService.updateTeam(teamName, mailGroup, description, date, team.id,null,null, null)
		assert Team.count() == 1
		assertEquals(team.teamName, "abc")
		assertEquals(team.mailGroup, "abc@gmail.com")
	}
	void testDelete(){
		TeamService teamService = new TeamService()
		List<Tracking> trackingList = Tracking.list()
		def team = Team.findByTeamName('Ant')
		println "team name"+ team.teamName
		teamService.deleteTeam(team)
		assert Team.count() == 1
	}
}
